package com.naxian.controller.index;

import com.naxian.pojo.Company;
import com.naxian.pojo.Recruit;
import com.naxian.service.company.CompanyService;
import com.naxian.service.index.IndexService;
import com.naxian.service.recruit.RecruitService;
import com.naxian.util.JsonResult;
import com.naxian.vo.index.IndexVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;


@Controller
public class IndexRecruitController {
    @Autowired
    private IndexService indexService;
    @Autowired
    private CompanyService companyService;

    @Autowired
    private RecruitService recruitService;
//首页渲染
    @PostMapping("index/get")
    @ResponseBody
    public JsonResult getRecruit(){
    /*查询所有工作*/
    List<Recruit> recruitList = recruitService.getAll();
    List<IndexVO> indexVOList = new ArrayList<>();
    /*每个工作对象对应一个公司对象 放入map中 */
        for (Recruit recruit :recruitList) {
            Company company = companyService.getById(recruitService.getByRecruitId(recruit.getRecId()).getCompanyId());
            IndexVO indexVO = new IndexVO(recruit.getRecId(),recruit.getRecName(),recruit.getRecJobSalary(),recruit.getRecJobExperience(),
                    recruit.getEducation(),recruit.getKwd(),company.getCompanyName(),company.getCompanySize(),
                    company.getCompanyType(),company.getCompayAddress());
            indexVOList.add(indexVO);
        }
        System.out.println(indexVOList.size());
    return new JsonResult(0,null,indexVOList);
}
}

